package edu.uta.cfl.data;

import java.util.ArrayList;

import edu.uta.cfl.engine.constraint.ChocoContext;

public class SUT {
	private String name;

	private String initialMessage;

	// the parameters are stored in the same order as they appear in
	// the configuration file.
	private ArrayList<Parameter> parameters;

	// existing test set
	private TestSet ts;

	private ArrayList<Combo>[] suspiciousCombos;

	private ArrayList<Component>[] suspiciousComponents;

	private ArrayList<Combo> testGen4TheseCmb;

	private ArrayList<String> constraints;

	private int strength;
	private ChocoContext choco;

	private ArrayList<Combo>[] validCombos;

	private ArrayList<Combo>[] invalidCombos;

	public static enum SUTState {
		continuing, failureInducing, noImprovement, notFound, expansion, InducingTest
	};

	private SUTState status;

	public SUT() {
		this.parameters = new ArrayList<Parameter>();
		this.ts = new TestSet();
		this.constraints = new ArrayList<String>();

		this.status = SUTState.continuing;
		this.setChoco(new ChocoContext());
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setParameters(ArrayList<Parameter> parameters) {
		this.parameters = parameters;

	}

	public ArrayList<Parameter> getParameters() {
		return parameters;
	}

	public void setTs(TestSet ts) {
		this.ts = ts;
	}

	public TestSet getTs() {
		return ts;
	}

	public void setSuspiciousCombos(ArrayList<Combo>[] suspiciousCombos) {
		this.suspiciousCombos = suspiciousCombos;
	}

	public ArrayList<Combo> getSuspiciousCombos(int len) {
		if (len > 0)
			return suspiciousCombos[len - 1];
		else
			return null;
	}

	public void setStrength(int strength) {
		this.strength = strength;

	}

	public int getStrength() {
		return strength;
	}

	public void setSuspiciousComponents(
			ArrayList<Component>[] suspiciousComponents) {
		this.suspiciousComponents = suspiciousComponents;
	}

	public ArrayList<Component> getSuspiciousComponents(int len) {
		return suspiciousComponents[len - 1];
	}

	public void addParameter(Parameter prm) {
		this.parameters.add(prm);
	}

	public int getParameterIndex(Parameter parameter) {
		return this.parameters.indexOf(parameter);
	}

	public void addSpcCombo(Combo cmb) {
		this.suspiciousCombos[cmb.getSize() - 1].add(cmb);
	}

	public void addSpcComponent(Component cmp, int len) {
		getSuspiciousComponents(len).add(cmp);
	}

	public void setStatus(SUTState status) {
		this.status = status;
	}

	public SUTState getStatus() {
		return status;
	}

	public void setConstraints(ArrayList<String> constraints) {
		this.constraints = constraints;
	}

	public ArrayList<String> getConstraints() {
		return constraints;
	}

	public void addConstraint(String con) {
		this.constraints.add(con);
	}

	public void setChoco(ChocoContext choco) {
		this.choco = choco;
	}

	public ChocoContext getChoco() {
		return choco;
	}

	public void setValidCombos(ArrayList<Combo> validCombos, int len) {
		this.validCombos[len - 1] = validCombos;
	}

	public ArrayList<Combo> getValidCombos(int len) {
		return validCombos[len - 1];
	}

	public void setInvalidCombos(ArrayList<Combo> invalidCombos, int len) {
		this.invalidCombos[len - 1] = invalidCombos;
	}

	public ArrayList<Combo> getInvalidCombos(int len) {
		return invalidCombos[len - 1];
	}

	public void newCmbCmpLst(int len) {
		this.suspiciousCombos[len - 1] = new ArrayList<Combo>();
		this.suspiciousComponents[len - 1] = new ArrayList<Component>();
	}

	public void initiateArrayLsts() {
		this.suspiciousCombos = new ArrayList[this.parameters.size()];
		this.suspiciousComponents = new ArrayList[this.parameters.size()];

		for (int i = 0; i < this.strength; i++) {
			this.suspiciousCombos[i] = new ArrayList<Combo>();
			this.suspiciousComponents[i] = new ArrayList<Component>();
		}

		this.validCombos = new ArrayList[this.parameters.size()];
		this.invalidCombos = new ArrayList[this.parameters.size()];
		for (int i = 0; i < this.parameters.size(); i++) {
			this.validCombos[i] = new ArrayList<Combo>();
			this.invalidCombos[i] = new ArrayList<Combo>();
		}
	}

	public void setTestGen4TheseCmb(ArrayList<Combo> testGen4TheseCmb) {
		this.testGen4TheseCmb = testGen4TheseCmb;
	}

	public ArrayList<Combo> getTestGen4TheseCmb() {
		return testGen4TheseCmb;
	}

	// Jagan test code begins
	public void setInitialDisplayMessage(String msg) {
		this.initialMessage = msg;
	}

	public String getInitialDisplayMessage() {
		return initialMessage;
	}

}
